/*
 * readline.h
 *
 *  Created on: Jul 28, 2010
 *      Author: Pierre Lindenbaum PhD
 *              plindenbaum@yahoo.fr
 *              http://plindenbaum.blogspot.com
 *              
 */

#ifndef U915_IO_ESCAPE_H_
#define U915_IO_ESCAPE_H_


#include <iostream>
#include <string>
#include <cstring>
namespace u915 { namespace io {



class escape
	{
	private:
	    const char* s;
	    std::size_t len;
	public:
	    escape(const char* s):s(s),len(std::strlen(s))
		{

		}
	    escape(const char* s,std::size_t len):s(s),len(len)
		{

		}
	    escape(const std::string& s):s(s.c_str()),len(s.size())
		{
		}
	    ~escape()
		{
		}
	    friend std::ostream& operator << (std::ostream& out,const escape& o);
	};

std::ostream& operator << (std::ostream& out,const escape& o)
    {
    for(std::size_t i=0;i< o.len;++i)
	{
	switch(o.s[i])
	    {
	    case '\'': out << "\\\'"; break;
	    case '\"': out << "\\\""; break;
	    case '\\': out << "\\\\"; break;
	    case '\n': out << "\\n"; break;
	    case '\t': out << "\\t"; break;
	    case '\r': out << "\\r"; break;
	    default: out << o.s[i]; break;
	    }
	}
    return out;
    }


}}//namespaces

#endif /* TOKENIZER_H_ */
